package com.ftwj.demo.permission.service.impl;

import java.util.Map;


import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ftwj.demo.permission.dao.OperateDao;
import com.ftwj.demo.permission.dao.UserDao;
import com.ftwj.demo.permission.entity.OperateBean;
import com.ftwj.demo.permission.entity.UserBean;
import com.ftwj.demo.permission.service.OperateService;

/**
*
* <p>Title: OperateServiceImpl</p>  
* <p>Description: 日志管理业务实现类</p>
* <p>Copyright: Copyright (c) 2020 </p>  
* <p>Company: 兰州飞天网景信息产业有限公司</p>    
* @author WangSLi
* @date 2020年4月4日 下午5:59:14
* @version V1.0
 */
@Service
public class OperateServiceImpl extends ServiceImpl<OperateDao, OperateBean> implements OperateService {
	
	@Autowired
	private OperateDao dao;
	@Autowired
	private UserDao userDao;

	@Override
	public IPage<Map<String, Object>> pageMaps(IPage<OperateBean> page,String time1,String time2,String moduleName,String userName) {
		OperateBean operate=new OperateBean();
		operate.setModuleName(moduleName);
		if(!StringUtils.isEmpty(userName)) {
			QueryWrapper<UserBean> qW = new QueryWrapper<>();
			qW.eq("show_name", userName);
			UserBean user = userDao.selectOne(qW);
			if(user != null) {
				operate.setCreateUser(user.getUserId());
			}
		}
		QueryWrapper<OperateBean> queryWrapper=new QueryWrapper<OperateBean>();
		if(time1 != null) {
			queryWrapper.ge("create_time", time1);
		}
		if (time2 != null) {
			queryWrapper.le("create_time", time2);
		}
		if(!StringUtils.isEmpty(operate.getModuleName())) {
			queryWrapper.like("module_name", operate.getModuleName());
		}
		if(operate.getCreateUser() != null) {
			queryWrapper.eq("create_user", operate.getCreateUser());
		}
		IPage<Map<String, Object>> data = dao.selectMapsPage(page, queryWrapper);
		return data;
	}

	@Override
	public Integer deleteByDate(String time1, String time2) {
		QueryWrapper<OperateBean> queryWrapper = new QueryWrapper<>();
		time1 = time1.replace("T", " ").replace(".000Z", "");
		time2 = time2.replace("T", " ").replace(".000Z", "");
		queryWrapper.ge("create_time", time1);
		queryWrapper.le("create_time", time2);
		return dao.delete(queryWrapper);
	}
	

}
